-- DELETE FROM mail_receivedmessage
-- select * from mail_receivedmessage
INSERT INTO mail_receivedmessage
SELECT 
newid() AS [Id],case len(convert(varchar(10),comid))
    when 5 then '00000000-0000-0000-0000-0000000' + convert(varchar(10),comid) 
    when 4 then '00000000-0000-0000-0000-00000000' + convert(varchar(10),comid) 
    when 3 then '00000000-0000-0000-0000-000000000' + convert(varchar(10),comid) 
    when 2 then '00000000-0000-0000-0000-0000000000' + convert(varchar(10),comid) 
    when 1 then '00000000-0000-0000-0000-00000000000'+ convert(varchar(10),comid) 
    end AS  [From],'00000000-0000-0000-0000-00000' + convert(varchar(7),userid) AS [To],substring(letterdetail,0,30) AS [Subject],letterdetail AS [Body],CreatedDate AS [DateReceived],CreatedDate AS [DateSent],0 as FlagFROM srv_lnk.nchr2008.dbo.MyInterview
--where userid in (select right(id,7) from cat_jobseeker) and userid <> 0 AND CREATEDDATE >'2012-1-1'
where userid in (select right(id,7) from cat_jobseeker) and userid <> 0 

--SELECT TOP 10 * FROM srv_lnk.nchr2008.dbo.MyInterview
